package 实战Java高并发程序设计;

public class C01MultiThreadLong {

    public static long t = 0;

    public static class Change implements Runnable {

        private long to;

        public Change(long to) {
            this.to = to;
        }

        @Override
        public void run() {
            while (true) {
                C01MultiThreadLong.t = to;
                Thread.yield();
            }
        }
    }

    public static class Read implements Runnable {

        @Override
        public void run() {
            while (true) {
                long tmp = C01MultiThreadLong.t;
                if (tmp != 111L && tmp != -999L && tmp != 333L && tmp != -444L) {
                    System.out.println(tmp);
                }
                Thread.yield();
            }
        }
    }

    public static void main(String[] args) {
        new Thread(new Change(111L)).start();
        new Thread(new Change(-999L)).start();
        new Thread(new Change(333L)).start();
        new Thread(new Change(-444L)).start();
        new Thread(new Read()).start();
    }
}
